package cn.xiaobai.j2exe.utils;

import java.io.File;
import java.io.IOException;

/**
 * cmd 执行工具
 *
 * @Author yangdaji
 * @Date 2024/1/2
 * @PackageName cn.xiaobai.j2exe.utils
 * @ClassName CommandUtils
 */
public class CommandUtils {

    /**
     * 隐藏文件
     *
     * @param path 文件路径
     */
    public static void hideFile(File path) {
        exe("attrib +s +h " + path);
    }

    /**
     * 显示文件
     *
     * @param path 文件路径
     */
    public static void nonHideFile(File path) {
        exe("attrib -s -h " + path);
    }


    private static void exe(String command) {
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec(command);
        } catch (IOException e) {
            System.err.println("dos exe fail: " + e.fillInStackTrace());
        }
    }
}
